#include "SharedTemplates/Any.hpp"
#include <vector>
void Test01()
{
    class TestA
    {
    public:
        int a;
        int b;
        int c;
    };
    Any n;
    auto r = n.IsNull();
    std::cout << __LINE__ << " " << r << std::endl;

    std::string s1 = "hello";
    try
    {
        n = s1;
    }
    catch (std::exception e)
    {
        std::cout << e.what() << std::endl;
    }
    
    try
    {
        std::cout << n.AnyCast<int>() << std::endl;
    }
    catch (std::exception e) {

    }

    Any n1 = 1;
    std::cout << n1.Is<int>() << std::endl;
    TestA test{ 1,2,3 };
    Any n2(test);
    if (n2.Is<TestA>())
    {
        TestA myTest = n2.AnyCast<TestA>();
        std::cout << myTest.a << " " << myTest.b << " " << myTest.c << std::endl;
    }
    std::vector<Any> anys;
    anys.emplace_back(Any(123));
    anys.emplace_back(Any(123.1));
    anys.emplace_back(Any(std::string("1234")));
    anys.emplace_back(n);
    anys.emplace_back(n1);
    anys.emplace_back(n2);


    for (const Any& item : anys)
    {
        if (item.IsNull()) continue;
        if (item.Is<int>())
        {
            std::cout << "Integer: " << item.AnyCast<int>() << std::endl;
        }
        else if (item.Is<double>())
        {
            std::cout << "Double: " << item.AnyCast<double>() << std::endl;
        }
        else if (item.Is<std::string>())
        {
            std::cout << "String: " << item.AnyCast<std::string>() << std::endl;
        }
        else if (item.Is<char*>())
        {
            std::cout << "char*" << item.AnyCast<char*>() << std::endl;
        }
        else if (item.Is<TestA>())
        {
            TestA a = item.AnyCast<TestA>();
            std::cout << "TestA " << a.a << " " << a.b << " " << a.c << " " << std::endl;
        }
        else
        {
            std::cout << "Unknown type!" << std::endl;
        }
    }
}
int main()
{
    Test01();
	return 0;
}